package com.atom.module.coroutine.test

import com.atom.module.coroutine.cancel.suspendCancellableCoroutine
import com.atom.module.coroutine.core.delay
import com.atom.module.coroutine.core.launch
import com.atom.module.coroutine.scope.CoroutineScope
import com.atom.module.coroutine.scope.GlobalScope
import kotlin.coroutines.suspendCoroutine


fun main() {
    println("start")
    GlobalScope.launch {
        println("2 ${Thread.currentThread()}")
        test()
    }
    Thread.sleep(2000)
    println(" end  ${Thread.currentThread()}")
}

suspend fun main11() {
    GlobalScope.launch {
        val result : String = test()
        println("${result.javaClass}  ${result}")
    }.join()
}


suspend fun loadForResult(): String {
    delay(1000L)
    return "HelloWorld"
}

suspend fun test() = suspendCancellableCoroutine<String> {
    println("${it.hashCode()}   ${it.javaClass.name}")
    it.resumeWith(Result.success(it.javaClass.name))
}
